#include<bits/stdc++.h>
using namespace std;

int f[1005];
int v[1005], w[1005];

int main()
{
	int t, n, m;
	cin>>t;
	while(t--)
	{
		cin>>n>>m;
		memset(f, 0, sizeof f);
		for(int i = 1;i <= n;i++)
			cin>>v[i];
		for(int i = 1;i <= n;i++)
			cin>>w[i];
		
		for(int i = 1;i <= n;i++)
		{
			for(int j = m;j >= w[i];j--)
			{
				f[j] = max(f[j], f[j-w[i]]+v[i]);
			}
		}
		cout<<f[m]<<endl;
	}
	cout<<endl;
	system("pause");
	return 0;
}
